from jinja2 import filters
import time

# Jinja2 Filters
def timeformat(value, format='%Y-%m-%d %H:%M:%S'):
    return time.strftime(format, time.localtime(float(value)))


def datetimeformat(value):
    return str(value)


def get_article_url(value, path):
    article_url = path.format(value)
    return article_url


def d_getphone(value):
    return value.split()[0]


# For time format (Like: 1427682963.232542 or 1427682963)
filters.FILTERS['timeformat'] = timeformat
# For timedate formate (Like: ISODate("2015-03-30T10:26:13.733Z") )
filters.FILTERS['datetimeformat'] = datetimeformat
# For produce article_url
filters.FILTERS['get_article_url'] = get_article_url
filters.FILTERS['d_getphone'] = d_getphone